<?php
namespace app\index\controller;
//error_reporting('0');
class haitaoController extends \app\base\controller\BaseController
{
    public function index(){



    	//获取分类
        $this->list = obj("index/global", "controller")->malltype("y", "1", "category", "null");
		$sql = "select * from `{pre}category` where `mallType`=1 and ID in (select min(ID) from `{pre}category` group by `mallName`)";
		$this->mall= obj('api/ApiData')->thisquery($sql);


        //半个小时热门
        $where_30m[]="`mallType` =  '0' and `date`> DATE_SUB(NOW(),INTERVAL  30 MINUTE)";
        $minute=obj("api/Apidata")->Data_Select("goods",$where_30m,"`id` DESC LIMIT 0 , 9");
        $this->minute=$minute;


        //热门点击
        $where_hot[]="1";
        $hot=obj("api/Apidata")->Data_Select("goods",$where_hot,"`view` DESC LIMIT 0 , 10");
        $this->hot=$hot;

        //10天收录
        $tenitems[]=" `mallType` =  '0' and  date_sub(curdate(), INTERVAL 7 DAY) <= date(`date`) ";
        $this->tenitems=obj("api/ApiData")->Data_Count("goods",$tenitems);

        //今日发布+预计
        $date=date("Y-m-d",time());
        $todaysenddata[]=" `mallType` =  '0' and  `date` LIKE  '%{$date}%'";
        $this->todaysenddata=obj("api/ApiData")->Data_Count("goods",$todaysenddata);
        $this->country="海淘";

        $where[]=" 1";
        $baseurl=url($route='index/haitao/index', $params=array());
        if($this->arg("list")){
       $wheres1[]="`id` ='{$this->arg("list")}'";
	    $cf1=obj("api/Apidata")->Data_Select("category",$wheres1);
         $where[]="`mallType` =  '1' AND  `1stCategoryName` ='{$cf1['1stCategoryName']}'";
        $baseurl=url($route='index/haitao/index/list=<list>', $params=array("list"=>$this->arg("list")));

        }

        if($this->arg("mall")){
			$wheres2[]="`id` ='{$this->arg("mall")}'";
	     $cf2=obj("api/Apidata")->Data_Select("category",$wheres2);
	 
         $where[]="`mallType` =  '1' AND  `mallName` ='{$cf2['mallName']}'";
         $baseurl=url($route='index/haitao/index/mall=<mall>', $params=array("mall"=>$this->arg("mall")));

        }

        if($this->arg("list") && $this->arg("mall")){
         $wheres3[]="`id` ='{$this->arg("list")}'";
	 $cf3=obj("api/Apidata")->Data_Select("category",$wheres3);
	 
         $where[]="`mallType` =  '1' AND  `mallName` =  '{$cf3['mallName']}' AND `1stCategoryName` =  '{$cf3['1stCategoryName']}'";
         $baseurl=url($route='index/haitao/index/list=<list>/mall=<mall>', $params=array("list"=>$this->arg("list"),"mall"=>$this->arg("mall")));
        }

        $Page = obj('api/ApiData')->PageIndex("50", "goods", $where, "`date` DESC", $baseurl);
        $this->Page = $Page;

      //  print_r($Page);

    	$this->display();
    }	

  }